<%--
  Created by IntelliJ IDEA.
  User: xianfei
  Date: 15-6-24
  Time: 下午2:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>周次划分</title>
    <style>
        .weekselected {
            background-color: #68b996;
        }

        .houseInfoselected {
            background-color: #68b996;
        }
    </style>
    <script src="/static/datepicker/WdatePicker.js"></script>
    <script>
        function showhouseweektime() {
            if ($("#houseweektime").is(':hidden')) {
                $("#houseweektime").show();
            }
            else {
                $("#houseweektime").hide();
            }
        }
        function houseInfoBind() {
            var houseInfo = $(".houseInfo");
            for (var j = 0; j < houseInfo.length; j++) {
                houseInfo.eq(j).bind('click', function () {
                    if ($(this).hasClass("houseInfoselected")) {
                        $(this).removeClass("houseInfoselected");
                    } else {
                        $(this).addClass("houseInfoselected");
                    }
                })
            }
        }

        function change() {
            var area = $("#houseBaseArea").val();
            $.ajax({
                url: '/house_week/findHouseInfo/' + area,
                type: 'get',
                dataType: 'json',
                success: function (data) {
                    $("#houseInfoContent").html(data);
                    houseInfoBind();
                }, error: function () {
                    alert('error');
                }
            })
        }
        function updatehouseweektime(houseweektimeguid, status) {
            var start = $("#start_" + status).val();
            var end = $("#end_" + status).val();
            $.ajax({
                url: '/house_week/updatehouseweektime/',
                type: 'POST',
                dataType: 'json',
                data: {start: start, end: end, houseweektimeguid: houseweektimeguid},
                success: function (data) {
                    alert("修改成功");
                }
            })
        }

        function addhouseweektime(houseWeekguid) {
            var start = $("#addStart").val();
            var end = $("#addEnd").val();
            var time = start + "," + end;
            $.ajax({
                url: '/house_week/divide_time',
                type: 'POST',
                dataType: 'json',
                data: {time: time, houseWeekGuid: houseWeekguid},
                success: function (data) {
                    location.reload();
                }
            })
        }

    </script>
</head>
<body>
</br>
</br>
</br>
</br>
<form:form commandName="houseWeekDTO" action="/house_week/updatebase" enctype="multipart/form-data">
    <form:hidden path="guid"/>
    <table class="table">
        <tr>
            <td>
                <label>度假屋:</label><span>${houseName}</span>
            </td>
            <td>
                    <%--<select>--%>
                    <%--<c:forEach items="${houseInfoDTOs}" var="list">--%>
                    <%--<option>dujiawu</option>--%>
                    <%--</c:forEach>--%>
                    <%--</select>--%>
                <label>周次:</label><span>${houseWeekDTO.name}</span>
            </td>
            <td>
                <label>已售:</label><span> ${houseWeekDTO.soldNum}</span>
            </td>
        </tr>
        <tr>
            <td>
                <label>总库存:</label><form:input path="totalNum"/>
            </td>
            <td>
                <label>价格:</label><form:input path="price"/>
            </td>
            <td>
                <label>描述:</label><form:input path="description"/>
            </td>
        </tr>
    </table>
    <input type="submit" value="保存基本信息" class="btn btn-success"/>
</form:form>
<hr/>
<input type="button" onclick="showhouseweektime()" value="显示/隐藏具体划分时间" class="btn btn-success">
<br>
<br>

<div id="houseweektime">
    <c:forEach items="${houseWeekDTO.houseWeekTimeDTOs}" var="houseWeekTimeDTO" varStatus="status">
        <div class="col-xs-6">
            开始：<input type="text" class="Wdate"
                      onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'end_${status.index}\');}'})"
                      value="${houseWeekTimeDTO.start}" id="start_${status.index}"/>&nbsp;
            结束：<input type="text" class="Wdate"
                      onFocus="WdatePicker({minDate:'#F{$dp.$D(\'start_${status.index}\');}'})"
                      value="${houseWeekTimeDTO.end}" id="end_${status.index}"/>
            <a href="javascript:updatehouseweektime('${houseWeekTimeDTO.guid}','${status.index}')">修改</a>
            <a href="/house_week/delhouseweektime/${houseWeekTimeDTO.guid}/${houseWeekDTO.guid}">删除</a>
        </div>
    </c:forEach>
    <div class="col-xs-12" style="border-top: 1px solid #000;margin-top: 50px;padding-top: 50px;">
        开始：<input type="text" id="addStart" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'addEnd\');}'})">&nbsp;
        结束：<input type="text" id="addEnd" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'addStart\');}'})">
        <a href="javascript:addhouseweektime('${houseWeekDTO.guid}')">添加</a>
    </div>

</div>
</body>
</html>